package gwtadmin.client.wsdltree;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;

@SuppressWarnings("serial")
public class UniqList<T extends Wt> extends ArrayList<T> implements List<T>,IsSerializable {
	public UniqList() {
		super();
	}
	
	/**
	 * Adds new item to list ts if there's don't have it.
	 * 
	 * @param t - item to add
	 * @param ts - list where to add
	 * @return <b>True</b> if adding is happened.
	 */
	public boolean add(T t) {
		if (t == null || contains(t))
			return false;
		
		super.add(t);
		return true;
	}
	
	@SuppressWarnings("unchecked")
	public T get(QName qname) {
		T[] list = (T[]) toArray();
		for (T t : list) {
			if (t.qname.equals(qname))
				return t;
		}
		
		return null;
	}
	
	static public <T extends Wt> T get(QName qname, List<T> list) {
		for (T t : list) {
			if (t.qname.equals(qname))
				return t;
		}
		
		return null;
	}
}
